from aiogram import Router, Bot
from aiogram.filters import CommandStart
from aiogram.types import Message
import re
import random

from utilities.sensor import sensor_temp, triger_temp
from config_data.config import load_config


router: Router = Router()

def my_start_filter(message: Message) -> bool:
    return message.text and re.findall(r"^\d+(-\d+)+$", message.text)

@router.message(CommandStart())
async def process_start_command(message: Message):

    await message.answer(text="Здарова были 👋🏾")



@router.message(my_start_filter)
async def process_start_command(message: Message):
    x, y = map(int,message.text.split("-"))
    await message.answer(text=str(random.randint(x, y)))

@router.message(lambda x: x.text and x.text.lower()=="темп")
async def process_start_command(message: Message):
    await message.answer(text=sensor_temp())

async def send_message_temp(bot: Bot):
    t = load_config().max_temp.temp
    if triger_temp(t):
        msg = f"Превышено максимальное значение {t}&#176;C\n"
        await bot.send_message(text=msg+sensor_temp(), chat_id=load_config().user_id.id)